
import { _decorator, Component, Node, Vec3, tween, Tween, } from 'cc';
import { Monster } from './Monster';
const { ccclass, property } = _decorator;

/**
 * 怪物的视图类,用于控制怪物的表现和动画等
 */
@ccclass('MonsterView')
export class MonsterView extends Component {
    @property({
        type: Boolean,
        displayOrder: 1,
    })
    //怪物是否空中类型,为true表示是.
    isFlyMonster: boolean = false

    //敌人的tween动画实例
    private _tween: Tween<Node> = null!;
    private _owner: Monster = null!;
    public init(mons: Monster) {
        this._owner = mons
    }
    //停止(终端)tween动画
    public stopAllTweens() {

    }

    //移动到目标点
    public MoveToTarget(target: Vec3, time: number, cb: Function) {
        this.stopMove()
        this._tween = tween(this.node)
            .to(time, { position: target })
            .call(() => {
                cb && cb();
            })
            .start();

    }

    //停止怪物的移动动画.
    public stopMove() {
        if (this._tween) {
            this._tween.stop();

        }
    }

    public dispose() {
        this.node.destroy()
    }


    //受伤函数
    public onHurt() {
        this._owner.onHurt();
    }
}


